﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using A2DFramework.MVCFramework.Descriptors;

namespace A2DFramework.MVCFramework.Factories
{
    class MethodFactory
    {
        internal static MethodDescriptor Resolve(ControllerDescriptor controllerDescriptor, System.Web.HttpContext context)
        {
            string action=context.Request.QueryString["action"];
            if(action==null||action.Trim().Length==0)
                throw new Exception("Action参数必须存在，否则无法判断调用的是哪个静态方法。");

            foreach (var md in controllerDescriptor.MethodDescriptors)
            {
                if (md.MethodName.Equals(action, StringComparison.OrdinalIgnoreCase))
                    return md;
            }

            return null;
        }
    }
}
